package com.bruceewu.galleryphoto.bean;

import android.util.Pair;

import com.bruceewu.galleryphoto.utis.FileUtils;

import java.io.File;

public class ImageBean {
    private File file;
    private int width;
    private int height;
    private String size;//单位 M

    public static ImageBean newInstance(File file) {
        ImageBean item = new ImageBean();
        item.file = file;
        Pair<Integer, Integer> scaledSize = FileUtils.scaledSize(file.getAbsolutePath());
        if (scaledSize != null) {
            item.width = scaledSize.first;
            item.height = scaledSize.second;
        }
        item.size = FileUtils.size(file);
        return item;
    }

    public String path() {
        return file.getAbsolutePath();
    }

    public String dir() {
        File parent = file.getParentFile();
        if (parent != null) {
            return parent.getAbsolutePath();
        } else {
            return path();
        }
    }

    public String name() {
        return file.getName();
    }

    public int width() {
        return width;
    }

    public int height() {
        return height;
    }

    public String tip() {
        return String.format("%s\n%s\n%s", dir(), name(), size);
    }
}
